<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.code" placeholder="股票代码" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.stockName" placeholder="名称" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.market" style="width: 140px" class="filter-item" @change="handleFilter">
        <el-option v-for="item in marketOptions" :key="item.key" :label="item.label" :value="item.key" />
      </el-select>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="ID" prop="id" sortable="custom" align="center" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="名称" prop="name" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.stockName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="股票代码" prop="code" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.code }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所属市场" prop="spell" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span v-if=" scope.row.market === 'sh' ">上海</span>
          <span v-if=" scope.row.market === 'sz' ">深圳</span>
        </template>
      </el-table-column>
      <el-table-column label="收盘价" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.closePrice }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最高价" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.maxPrice }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最低价" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.minPrice }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开盘价" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.openPrice }}</span>
        </template>
      </el-table-column>
      <el-table-column label="前收盘" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.beforeClose }}</span>
        </template>
      </el-table-column>
      <el-table-column label="涨跌额" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.changeAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="涨跌幅" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.changeRange }}</span>
        </template>
      </el-table-column>
      <el-table-column label="成交量" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.tradeNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="成交金额" prop="status" sortable="custom" align="center" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.tradeMoney }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.size" @pagination="getList" />
  </div>
</template>

<script>
import request from '@/utils/request'
// eslint-disable-next-line no-unused-vars
import Pagination from '@/components/Pagination'
import waves from '@/directive/waves' // waves directive
export function pageList(data) {
  return request({
    url: '/api/shareadmin/share/stockIndex/page',
    method: 'post',
    data
  })
}
export default {
  name: 'ComplexTable',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        currentPage: 1,
        size: 20,
        code: null,
        stockName: null,
        closePrice: null,
        id: null,
        market: null,
        maxPrice: null,
        minPrice: null,
        openPrice: null,
        changeAmount: null,
        changeRange: null,
        tradeNum: null,
        tradeMoney: null
      },
      marketOptions: [{ label: '深圳', key: 'sz' }, { label: '上海', key: 'sh' }],
      showReviewer: false,
      temp: {
        id: undefined,
        importance: 1,
        remark: '',
        timestamp: new Date(),
        title: '',
        type: '',
        status: 'published'
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: 'Edit',
        create: 'Create'
      },
      dialogPvVisible: false,
      pvData: [],
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      downloadLoading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      console.log(this.listQuery)
      pageList(this.listQuery).then(response => {
        this.list = response.data.records
        this.total = response.data.total
        console.log(response)
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleFilter() {
      this.listQuery.currentPage = 1
      this.getList()
    }
  }
}
</script>

